#ifndef FORMSRV_H
#define FORMSRV_H

#include <QWidget>
#include "myserver.h"
#include <QModelIndex>
#include <QMutexLocker>
#include <QMutex>
#include <QSize>
#include "MsgDef.h"
#include <QMap>
QString gb2312ToUtf8(const char* szString , int nSize = -1);

namespace Ui {
class FormSrv;
}
enum RowState{onLine,offLine,selected};
class FormSrv : public QWidget
{
    Q_OBJECT
    
public:
    explicit FormSrv(QWidget *parent = 0);
    ~FormSrv();
public slots:
    void slot_InsertClient(int Id,QString ip, QString laneNum, QString msg, int &rowNum);
    void slot_UpdateClientInitState(int rowNum,QString laneNum,QString deviceState,QString useVpr,QString checkTimeOut,QString h5Limit);
    void slot_DisplayLogMsg(int disSocket, QString msg);
    void slot_UpdateClientNetState(int rowNum,const QString state);
    void slot_UpdateClientID(int rowNum,int ID);
    void slot_UpdateVehQueue(int disSocket,myQueue vehQue,int vehCount);
    void slot_UpdateCurVeh(int disSocket,myVehInfo curVeh);
    void slot_UpdateClientMsg(int rowNum,QString msg);
    //将ip与对应行号保存到map中
    void slot_InsetNewIpAndRow(const QString &ip,int rowNum);
    bool CheckexistIp(const QString &ip, int &rowNum, const int &socketDes);
    //双击列表或者路段中的车道时触发
    void slot_SelectToShowDetail(const int &rowNum);
    //打开程序时加载路段excel表格
    void slot_LoadRoadInfo();
signals:
    void sig_SendMsg(int socketDes,QString msg);
private slots:
    void on_but_StartSrv_clicked();

    //void on_but_Send_clicked();

    void on_tableWidget_doubleClicked(const QModelIndex &index);

    void on_pushButton_clicked();

    void on_but_ControlView_clicked();


    void on_but_RoadInfo_clicked();

    void on_treeWidget_2_doubleClicked(const QModelIndex &index);

protected:
    void closeEvent(QCloseEvent *event);
    void paintEvent(QPaintEvent *event);
private:
    Ui::FormSrv *ui;
    MyServer *m_Srv;
    int m_nCurrentSocket;
    int m_nCurrentRowNum;
    QMutex mutex;
    QMutex m_IpAndRowMutex;
    QMutex m_ResetMutex;
    QMutex m_SetColMutex;
    void ResetVehQueue();
    void ResetCurVeh();
    void ResetUseState(int rowNum);
    void SetRowColor(int rowNum, RowState state);
    QString GetDisplayStr(int vehType,QPixmap &img);
    QSize mainSize;
    QSize panelSize;
    bool m_excelIsOpen;
    //
    QMap<QString,int> m_Ip2RowNumMap;
public:
    QString getClientNetState(int rowNum);
    int getClientID(int rowNum);
    void setTableVisible(bool state = false);
    void SetLogInfo(QString LogName,QString logTime);
};
//static FormSrv *srvForm = NULL;
FormSrv* getForm();
#endif // FORMSRV_H
